package com.white.controller;

import com.white.bean.Block;
import com.white.bean.User;
import com.white.mapper.BlockMapper;
import com.white.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class BlockController {
    @Autowired
    BlockMapper blockMapper;
    @Autowired
    UserService userService;
    @GetMapping("/block/{blockUserId}")
    public void block(@CookieValue(UserController.LOGIN_USER_ID) Long userId,
                       @PathVariable("blockUserId") Long blockUserId) {
        Block block = new Block(userId, blockUserId);
        blockMapper.create(block);
    }


    @GetMapping("/getBlock")
    @ResponseBody
    public List<User> getBlock(@CookieValue(UserController.LOGIN_USER_ID) Long userId) {
        return userService.getBlock(userId);
    }


    @GetMapping("/removeBlock/{blockUserId}")
    public void removeBlock(@CookieValue(UserController.LOGIN_USER_ID) Long userId,
                      @PathVariable("blockUserId") Long blockUserId) {
        Block block = new Block(userId, blockUserId);
        blockMapper.myDelete(block);
    }
}
